//
//  MKOrginalView.m
//  Weibo_OC
//
//  Created by mac on 16/1/23.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "MKOrginalView.h"
#import "UILabel+MKLabel.h"
#import "MKStatues.h"
#import "MKStatuesUser.h"
#import <UIImageView+WebCache.h>
#import <Masonry.h>

@interface MKOrginalView ()

@property (strong, nonatomic) UIImageView *iconImageView;

@property (strong, nonatomic) UIImageView *mbImageView;

@property (strong, nonatomic) UIImageView *refyImageView;

@property (strong, nonatomic) UILabel *nameLabel;

@property (strong, nonatomic) UILabel *timeLabel;

@property (strong, nonatomic) UILabel *sourceLabel;

@property (strong, nonatomic) UILabel *contentLabel;
@end

@implementation MKOrginalView

- (void)setStatue:(MKStatues *)statue {
    _statue = statue;
    
    [self.iconImageView sd_setImageWithURL:statue.user.profile_imageURL placeholderImage:[UIImage imageNamed:@"avatar_default_big"]];
    self.nameLabel.text = statue.user.screen_name;
    if (statue.user.mbrankImage) {
        self.nameLabel.textColor = [UIColor orangeColor];
    } else {
    
        self.nameLabel.textColor = [UIColor darkGrayColor];
    }
    self.mbImageView.image = statue.user.mbrankImage;
    self.refyImageView.image = statue.user.verified_type_image;
    self.contentLabel.text = statue.text;

}


- (instancetype)init {
    
    if (self = [super init]) {
        [self setupUI];
    }
    
    return self;
}

- (void)setupUI {
    
    [self addSubview:self.iconImageView];
    [self addSubview:self.refyImageView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.mbImageView];
    [self addSubview:self.timeLabel];
    [self addSubview:self.sourceLabel];
    [self addSubview:self.contentLabel];
    
    // 自动布局 头像
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(10);
        make.left.equalTo(self.mas_left).offset(10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
    }];
    
    //自动布局 认证图片
    [self.refyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconImageView.mas_bottom);
        make.right.equalTo(self.iconImageView.mas_right);
    }];
    
    //自动布局 名字
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.mas_top);
        make.left.equalTo(self.iconImageView.mas_right).offset(10);
        
    }];
    
    //自动布局 会员图片
    [self.mbImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(10);
        make.centerY.equalTo(self.nameLabel.mas_centerY);
    }];
    
    
    //自动布局 时间
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.iconImageView.mas_bottom);
        make.left.equalTo(self.nameLabel.mas_left);
        
    }];
    
    //自动布局 来源
    [self.sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.timeLabel.mas_top);
        make.left.equalTo(self.timeLabel.mas_right).offset(10);
    }];
    
    //自动布局 内容
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconImageView.mas_bottom).offset(10);
        make.left.equalTo(self.iconImageView.mas_left);
        make.right.equalTo(self.mas_right);
    }];
    
    //布局自动计算大小
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.contentLabel.mas_bottom);
    }];
}

#pragma mark -
#pragma mark - 懒加载头像
- (UIImageView *)iconImageView {
    
    if (nil == _iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.layer.cornerRadius = 20;
        _iconImageView.layer.masksToBounds = YES;
    }
    
    return _iconImageView;
}

#pragma mark -
#pragma mark - 懒加载 认证图片

- (UIImageView *)refyImageView {
    if (nil == _refyImageView) {
        _refyImageView = [[UIImageView alloc] init];
    }
    
    return _refyImageView;
    
}


#pragma mark -
#pragma mark - 懒加载名字
- (UILabel *)nameLabel {
    if (nil == _nameLabel) {
        _nameLabel = [[UILabel alloc] initWithTitle:@"" andWithTitleColor:[UIColor orangeColor] andWithFontSize:16 andWithMargin:10];
    }
    
    return _nameLabel;
}

#pragma mark -
#pragma mark - 懒加载 会员图片

- (UIImageView *)mbImageView {
    if (nil == _mbImageView) {
        _mbImageView = [[UIImageView alloc] init];
    }
    
    return _mbImageView;
}

#pragma mark -
#pragma mark - 懒加载时间
- (UILabel *)timeLabel {
    if (nil == _timeLabel) {
        _timeLabel = [[UILabel alloc] initWithTitle:@"22:22" andWithTitleColor:[UIColor orangeColor] andWithFontSize:14 andWithMargin:10];
    }
    
    return _timeLabel;
}

#pragma mark -
#pragma mark - 懒加载来源
- (UILabel *)sourceLabel {
    if (nil == _sourceLabel) {
        _sourceLabel = [[UILabel alloc] initWithTitle:@"104" andWithTitleColor:[UIColor lightGrayColor] andWithFontSize:14 andWithMargin:10];
    }
    
    return _sourceLabel;
}

#pragma mark -
#pragma mark - 懒加载内容
- (UILabel *)contentLabel {
    if (nil == _contentLabel) {
        _contentLabel = [[UILabel alloc] initWithTitle:@"" andWithTitleColor:[UIColor blackColor] andWithFontSize:20 andWithMargin:10];
    }
    
    return _contentLabel;
}





@end
